package com.sky.mapper;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 购物车表
 */
@Mapper
public interface ShoppingCartMapper {
    /**
     * 根据条件查询购物车的数据
     * @param shoppingCartDTO
     * @param userId
     * @return
     */
    ShoppingCart selectShoppingCart(ShoppingCartDTO shoppingCartDTO, Long userId);

    /**
     * 修改购物车中商品的数量
     * @param id
     */
    @Update("update sky_take_out.shopping_cart set number = number + #{count} where id = #{id}")
    void updateNumber(Long id ,int count);

    /**
     * 添加购物车
     * @param shoppingCart
     */
    void insertShoppingCart(ShoppingCart shoppingCart);

    /**
     * 根据userid查看用户购物车
     * @param userId
     * @return
     */
    @Select("select * from sky_take_out.shopping_cart where user_id = #{userId}")
    List<ShoppingCart> selectShoppingCartByUserId(Long userId);

    /**
     * 清空用户购物车
     * @param userId
     */
    @Delete("delete from sky_take_out.shopping_cart where user_id = #{userId}")
    void deleteShoppingCart(Long userId);

    /**
     * 根据id删除购物车
     * @param id
     */
    @Delete("delete from sky_take_out.shopping_cart where id = #{id}")
    void deleteShoppingCartById(Long id);
}
